﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UClaimDemageControlListEasyUI : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "UClaimDemageControlList";
            }
        }

        #region 属性 (查询条件)


        protected string ClaimsNumber
        {
            get
            {
                return GetRequestValue<string>("ClaimsNumber", "");

            }
        }
        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");

            }
        }

        protected string ShowAgentName
        {
            get
            {
                return GetRequestValue<string>("ShowAgentName", "");

            }
        }
        protected string DiffDuty
        {
            get
            {
                return GetRequestValue<string>("DiffDuty", "");
            }
        }

        protected string DownlineDateFrom
        {
            get
            {
                return GetRequestValue<string>("DownlineDateFrom", "");

            }
        }
        protected string DownlineDateTo
        {
            get
            {
                if (string.IsNullOrEmpty(DownlineDateFrom))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("DownlineDateTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(DownlineDateFrom).AddDays(1).ToShortDateString();
                    else
                        return todate;
                }

            }
        }
       
        #endregion

        protected string GetSQLWhere()
        {
            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(ClaimsNumber))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("ClaimsNumber", QueryOperatorsEnum.包含, ClaimsNumber);
                wheresql = sqlcommonFiled;
            }



            if (!string.IsNullOrEmpty(SerialNumber))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("SerialNumber", QueryOperatorsEnum.包含, SerialNumber);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }

            
            if (!string.IsNullOrEmpty(DownlineDateFrom))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("FaultDate", QueryOperatorsEnum.范围, DownlineDateFrom + "|" + DownlineDateTo);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }

            string sqlAgentName = "";
            if (!string.IsNullOrEmpty(ShowAgentName))
            {
                sqlAgentName = "'" + ShowAgentName + "'";
                sqlAgentName = sqlAgentName.Replace(",", "','");
                sqlAgentName = " agentname in (" + sqlAgentName + ")";
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlAgentName;
                }
                else
                {
                    wheresql = sqlAgentName;
                }
            }

            string dutySQL = "";
            if (!string.IsNullOrEmpty(DiffDuty))
            {
                dutySQL = QueryOperatorsEnumHelper.ConvertCommonOperator("DiffDuty", QueryOperatorsEnum.包含, DiffDuty);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + dutySQL;
                }
                else
                {
                    wheresql = dutySQL;
                }
            }

            return wheresql;
        }

        protected override string query()
        {
            DataTableCollection dts = UClaimDemageControlController.GetPagination(GetSQLWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);

            return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();
        }
    }
}